package com.tongji.housediy.model
{
	import com.tongji.housediy.events.commonEvent.ChangeData3D;
	import com.tongji.housediy.events.commonEvent.ExchangeDataEvent;
	import com.tongji.housediy.events.commonEvent.GridContainerEvent;
	import com.tongji.housediy.events.commonEvent.MoveCamera3D;
	import com.tongji.housediy.events.commonEvent.ResetRadioGroupEvent;
	import com.tongji.housediy.events.commonEvent.SetCompStateEvent;
	import com.tongji.housediy.events.commonEvent.ShowHideTitleWindowEvent;
	import com.tongji.housediy.events.TypeXMLAdminEvent;
	import com.tongji.housediy.events.UpdateRatioCompEvent;
	import com.tongji.housediy.events.UpdateViewControlEvent;
	
	import org.robotlegs.mvcs.Actor;
	
	/**
	 * 
	 * @author yanghanbing
	 * 2011/7/
	 */ 
	public class ViewModel extends Actor
	{
		[Inject]
		public var enableModel:CompEnableStateModel;
		
		[Inject]
		public var stateModel:RightCompStateModel;
		
		[Inject]
		public var indexModel:RightListStateModel;
		
		[Inject]
		public var viewControlModel:ViewControlModel;
		public function ViewModel()
		{
			super();
		}
		
		public function changeTo2DView():void
		{
			if (enableModel.is3DView == true)
			{				
				enableModel.is2DView = true;
				enableModel.is3DView = false;
				
				dispatch(new UpdateViewControlEvent(UpdateViewControlEvent.TWO_DIMENSION_VIEW));
				dispatch(new ExchangeDataEvent(ExchangeDataEvent.RESET_BORDER_CHILD));
				dispatch(new ChangeData3D(ChangeData3D.REMOVE_DATA));
				
				// 还原 网格 大小和滚动条位置
				//dispatch(new GridContainerEvent(GridContainerEvent.RETRIEVE_GRID_CONTAINER));
				
				// 还原 标尺组件 大小
				dispatch(new UpdateRatioCompEvent(UpdateRatioCompEvent.UPATE_RATIO_COMP, 4));
				
				// 还原 3D 按钮的 enable 状态
				dispatch(new SetCompStateEvent(SetCompStateEvent.SET_COMP_NORMAL_STATE));
				
				// 设置 RightControlComp state
				stateModel.state = "State1";
				
				// 设置 Layer4Comp selectedIndex
				indexModel.stateIndex = 0; 
				
				enableModel.isRightTabBtnEnable = true;
				
				dispatch(new ResetRadioGroupEvent(ResetRadioGroupEvent.RESET_WALL_RADIO));
				dispatch(new GridContainerEvent(GridContainerEvent.UPDATE_GRID_SCALE, viewControlModel.dimensionValue - viewControlModel.tempDimensionValue));
				viewControlModel.tempDimensionValue = viewControlModel.dimensionValue;
			}
		}
		
		public function changeTo3DView():void
		{
			if (enableModel.is2DView == true)
			{				
				enableModel.is2DView = false;
				enableModel.is3DView = true;
				
				dispatch(new UpdateViewControlEvent(UpdateViewControlEvent.THREE_DIMENSION_VIEW));
				dispatch(new ExchangeDataEvent(ExchangeDataEvent.UPDATE_EXCHANGE_MODEL));
				dispatch(new ShowHideTitleWindowEvent(ShowHideTitleWindowEvent.HIDE_TITLE_WINDOW));
				dispatch(new MoveCamera3D(MoveCamera3D.CAMERA_SELECT, viewControlModel.dimensionValue - 5));
				// 还原 网格 大小和滚动条位置
				//dispatch(new GridContainerEvent(GridContainerEvent.RETRIEVE_GRID_CONTAINER));
				//				
				//				// 设置 RightControlComp state
				//				stateModel.state = "State3";
				//				
				//				// 设置 Layer4Comp selectedIndex
				//				indexModel.stateIndex = 6;
				//				
				//				enableModel.isRightTabBtnEnable = false;
				//				
				// 设置 RightControlComp state
				stateModel.state = "State1";
				
				// 设置 Layer4Comp selectedIndex
				indexModel.stateIndex = 0;
				
				enableModel.isRightTabBtnEnable = true;
				
				// 重置 3D 类型 List1 内容
				dispatch(new TypeXMLAdminEvent(TypeXMLAdminEvent.UPDATE_WALL_LEVEL1_XML, "wall"));
				
				dispatch(new ResetRadioGroupEvent(ResetRadioGroupEvent.RESET_TAB_RADIO));
				dispatch(new ResetRadioGroupEvent(ResetRadioGroupEvent.RESET_BUILDING_RADIO));
				viewControlModel.tempDimensionValue = viewControlModel.dimensionValue;
			}
		}
	}
}